package com.mf.ergate.web.security.captcha;

import javax.servlet.http.HttpServletRequest;

/**
 * 验证码工具类
 */
public abstract class CaptchaUtils {

	//默认存储在session中的验证码Key
	private static final String SESSION_CAPTCHA_KEY = "SESSION_CAPTCHA_KEY";

	/**
	 * 设置session中的验证码
	 */
	public static String getCaptchaValue(HttpServletRequest request) {
		if (request != null && request.getSession() != null) {
			return (String) request.getSession().getAttribute(SESSION_CAPTCHA_KEY);
		}
		return null;
	}

	/**
	 * 获取session中的验证码
	 */
	public static void setCaptchaValue(HttpServletRequest request, String text) {
		if (request != null && request.getSession() != null) {
			request.getSession().setAttribute(SESSION_CAPTCHA_KEY, text);
		}
	}
}
